# 682：简单  棒球比赛

class Solution:
    # def calPoints(self, ops: List[str]) -> int:
    def calPoints(self, ops) -> int:
        sum = 0
        ret = []
        for c in ops:
            if not c.isalpha() and c != '+':
                sum += int(c)
                ret.append(c)
            elif c == 'C':
                num = int(ret.pop())
                sum -= num
            elif c == 'D':
                num = int(ret[-1])
                sum += num*2
                ret.append(num*2)
            else:
                score1 = int(ret[-1])
                score2 = int(ret[-2])
                ret.append(score1 + score2)
                sum += score2 + score1
            # print(sum)

        return sum


s = Solution()
print(s.calPoints(["1"]))


# class Solution:
#     def calPoints(self, ops: List[str]) -> int:
#         stk = []
#         for op in ops:
#             match op:
#                 case 'C':
#                     stk.pop()
#                 case 'D':
#                     stk.append(stk[-1] * 2)
#                 case '+':
#                     stk.append(stk[-1] + stk[-2])
#                 case _:
#                     stk.append(int(op))
#         return sum(stk)